package ltd.newbee.mall.order.controller;

import jakarta.annotation.Resource;
import ltd.newbee.mall.common.ApiResponse;
import ltd.newbee.mall.order.entity.Order;
import ltd.newbee.mall.order.entity.OrderItem;
import ltd.newbee.mall.order.service.OrderService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/orders")
public class OrderController {

    @Resource
    private OrderService orderService;

    @PostMapping
    public ApiResponse<String> create(@RequestBody List<OrderItem> items) {
        return ApiResponse.success(orderService.createOrder(items));
    }

    @GetMapping
    public ApiResponse<List<Order>> page(@RequestParam(defaultValue = "1") int page,
                                         @RequestParam(defaultValue = "10") int size) {
        return ApiResponse.success(orderService.findPage(page, size));
    }

    @GetMapping("/{orderNo}")
    public ApiResponse<List<OrderItem>> detail(@PathVariable String orderNo) {
        return ApiResponse.success(orderService.findItems(orderNo));
    }
}


